package com.vilinno.tlias.service.impl;

import com.vilinno.tlias.mapper.DeptMapper;
import com.vilinno.tlias.pojo.Dept;
import com.vilinno.tlias.service.DeptService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAll(){
        return deptMapper.findAll();
    }

    @Override
    public void deleteById(Integer deptId){
        deptMapper.deleteById(deptId);
    }

    @Override
    public void add(Dept dept){
        //1. 补全基础属性 createTime updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2.调用mapper接口方法
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer deptId){
        return deptMapper.getById(deptId);
    }

    @Override
    public void update(Dept dept){
        //补全基础数据
        dept.setUpdateTime(LocalDateTime.now());
        //调用mapper接口
        deptMapper.update(dept);
    }
}
